package com.example.classsify.controller;

import com.example.classsify.pojo.Classsify;
import com.example.classsify.service.ClaifyService;
import com.example.commons.result.CommonResult;
import com.example.commons.utils.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@CrossOrigin
public class ClifyController {

    @Autowired
    ClaifyService claifyService;

    /**
     * @Author 小江
     * @Description //TODO分类全查
     * @Date 21:02 2022/11/14
     **/
    @GetMapping("/classsifyList")
    public CommonResult businessList(String classificationName, Integer pageNum, Integer pageSize) {
        PageResult pageResult = new PageResult();
        pageResult.setPageNum(pageNum);
        pageResult.setPageSize(pageSize);
        PageResult pageResult1 = claifyService.classificationName(classificationName, pageResult);
        return CommonResult.ok(pageResult1);
    }

    /**
     * @Author 小江
     * @Description //TODO 分类添加/修改
     * @Date 21:25 2022/11/15
     **/
    @PostMapping("/classsifyinfo")
    public CommonResult classsifyinfo ( Classsify classsify,MultipartFile file) {

        int i = claifyService.classsifyinfo(classsify,file);
        if (i > 0) {
            return CommonResult.ok("添加成功");

        } else {
            return CommonResult.fail(9999, "添加失败");
        }
    }

    /**
     * @Author 小江
     * @Description //TODO 删除分类
     * @Date 10:31 2022/11/16
     **/
    @DeleteMapping("classsifyDel")
    CommonResult classsifyDel(Integer id){
        int i = claifyService.classsifyDel(id);
        if (i > 0) {
            return CommonResult.ok("删除用户信息成功");
        } else {
            return CommonResult.fail(9999, "删除用户信息失败");
        }
    }



}
